1073D - Berland Fair - CodeForces Solution


binary search brute force data structures greedy *1700

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define loopp(i,a,b) for(int i=a;i<b;i++)
#define loopn(i,a,b) for(int i=a;i>=0;i--)
#define pb push_back
using namespace std;



void solve(){
    int n;
    long long t;
    cin>>n>>t;
    vector<int> a(n);
    int minel=1e9;
    loopp(i,0,n) cin>>a[i], minel=min(minel,a[i]);
    
    long long ans=0;
    while(t>=minel){
        long long add=0;
        long long sum=0;
        for(int i=0;i<n;i++){
            if(a[i]<=t){
                sum+=1ll*a[i];
                t-=1ll*a[i];
                add++;
            }
        }
        ans+=add+(t/sum)*add;
        t%=sum;
    }
    cout<<ans<<endl;
    
    
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	solve();
	
	return 0;
}


Comments

Submit
0 Comments
More Questions

1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain